package com.zhouyibike.uu.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.zhouyibike.uu.R;
import com.zhouyibike.uu.entity.Threecity;

import java.util.ArrayList;

/**
 * Created by cc on 2017/5/3.
 */

public class Cityo1Adapter extends BaseAdapter {
    private Context context;
    private ArrayList<Threecity> list;

    public Cityo1Adapter(Context context, ArrayList<Threecity> list) {
        this.context = context;
        this.list = list;
    }
    public  void setList(ArrayList<Threecity>  list){
        this.list = list;
        notifyDataSetChanged();
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder = null;
        if (convertView == null) {// 如果是第一次显示该页面(要记得保存到viewholder中供下次直接从缓存中调用)
            convertView= LayoutInflater.from(context).inflate(R.layout.adapter_city_item,null);
            holder = new ViewHolder();
            // 以下为保存这一屏的内容，供下次回到这一屏的时候直接refresh，而不用重读布局文件
            holder.tv = (TextView) convertView.findViewById(R.id.tv_left_name);
            convertView.setTag(holder);
        } else {// 如果之前已经显示过该页面，则用viewholder中的缓存直接刷屏
            holder = (ViewHolder) convertView.getTag();
        }
        holder.tv.setText(list.get(position).getState());
        return convertView;
    }

    public final class ViewHolder {
        public TextView tv;
    }
}
